package com.zhw.controller;

import com.zhw.pojo.Book;
import com.zhw.pojo.BookDTO;
import com.zhw.pojo.PageBean;
import com.zhw.pojo.Result;
import com.zhw.service.BookService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
public class BookController {

    @Autowired
    BookService bookService;

    @GetMapping("getBook")
    public Result page( BookDTO bookDTO){
    log.info("获取信息图书信息：{}",bookDTO);
    PageBean pb=bookService.page(bookDTO);
    System.out.println(pb.getRecords());
    return Result.success(pb);
    }

    @GetMapping("getBookById")
    public Result getByID(String isbn){
        log.info("查询图书信息：{}",isbn);
        Book b=bookService.getByID(isbn);
        return Result.success(b);
    }

    @PostMapping("/save")
    public Result save(@RequestBody Book book){
        log.info("添加图书信息：{}",book);
        bookService.save(book);
        return Result.success();
    }

    @PutMapping("update")
    public Result update(@RequestBody Book book){
        log.info("修改图书信息：{}",book);
        bookService.update(book);

        return Result.success();
    }

    @DeleteMapping("delete")
    public Result delete(String isbn){
        log.info("删除书本信息：{}",isbn);
        bookService.delete(isbn);
        return Result.success();
    } @DeleteMapping("delete")


    public Result newMethod1(String isbn){
        log.info("删除书本信息：{}",isbn);
        bookService.delete(isbn);
        return Result.success();
    }



}
